﻿app.controller('FileCtrl', [
    '$scope', '$http', '$filter', 'httpPlus', '$interval', 'utils',
    function ($scope, $http, $filter, httpPlus, $interval, utils) {
        utils.setTitle('我的档案');

        $scope.showToast = false;
        var timer;
        var second = 1;
        $scope.personDetail = {
            name: "",
            chooseSex: "",
            birthday: "",
            tel: ""
        }
        $scope.sex = [
            {
                "name": "女",
                "id": 1
            },
             {
                 "name": "男",
                 "id": 2
             },
        ];
        $scope.saveMessage_click = function () {
            var postData = {
                _name: $scope.personDetail.name,
                _sex: $scope.personDetail.chooseSex,
                _birthday: $filter('date')($scope.personDetail.birthday, "yyyy-MM-dd"),
                _tel: $scope.personDetail.tel,
            };

            if ($scope.personDetail.name && $scope.personDetail.tel != undefined) {
                httpPlus
                    .RRRApi('MemberCenterPage/UpdateMemberDetailPage', postData)
                    .then(function () {
                        timer = $interval(function () {
                            if (second == 4) {
                                $interval.cancel(timer);
                                second = 1;
                                $scope.showToast = false;
                            } else {
                                $scope.showToast = true;
                                second++;
                            }
                        }, 1000);
                    }, function (error) {
                        alert(error);
                    });
            } else {
                alert("姓名或电话号码不能为空!");
            }

        }
        httpPlus
            .RRRApi('MemberCenterPage/InitMemberDetailPage', { _oid: "" })
            .then(function (data) {
                $scope.personDetail.name = data.Name;
                $scope.personDetail.chooseSex = data.Sex;
                $scope.personDetail.birthday = new Date(data.BirthDay.substr(0, 10));
                $scope.personDetail.tel = data.Phone;
            });
    }]);